package security.controller;


import exception.NoResultException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import security.entity.YxActor;
import security.entity.YxLogin;
import security.service.IYxActorService;
import security.service.IYxLoginService;
import security.util.RedisUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 优协主体用户表 前端控制器
 * </p>
 *
 * @author liyp
 * @since 2020-01-09
 */
@RestController
@RequestMapping("/yx-actor")
public class YxActorController {

    @Autowired
    IYxActorService yxActorService;

    @Autowired
    IYxLoginService loginService;

    @Autowired
    RedisUtil redisUtil;

    @GetMapping("cache")
    @Cacheable(cacheNames = "cache-actor-info",key="'userInfo:'+#userName")
    @ResponseBody
    public Object testCacheEnable(@RequestParam("userName") String userName){
        redisUtil.set("ceshi",userName);
        YxLogin yxLogin = loginService.selectByCode(userName);
        if(null == yxLogin){
            throw new NoResultException("没有对应账户信息");
        }
        YxActor yxActor = yxActorService.getById(yxLogin.getSaId());
        if(null != yxActor){
            Map<String,Object> map = new HashMap();
            map.put("userName",userName);
            map.put("passWord",yxActor.getPassword());
            return map;
        }
        return "没有数据";
    }
}
